import definedReactive from "./definedReactive";
import { methodsObj } from "./arrayMethods";
import { def } from "./utils";
import Dep from "./Dep";
import observe from "./observe";
export default class Observer {
  constructor(data) {
    this.dep = new Dep();
    def(data, "__ob__", this);
    if (Array.isArray(data)) {
      Object.setPrototypeOf(data, methodsObj);
      this.observeArray(data);
    } else {
      this.walk(data);
    }
  }
  walk(data) {
    for (let key in data) {
      definedReactive(data, key);
    }
  }
  observeArray(data) {
    for (var i = 0, l = data.length; i < l; i++) {
      observe(data[i]);
    }
  }
}
